package com.whfc.ms.api.fuum.controller;

import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.fuum.entity.AppProjectPlan;
import com.whfc.common.result.Result;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.fuum.service.MsProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目管理-方案管理
 *
 * @author dzg
 * @since 2025-09-23
 */
@RestController
@RequestMapping("/ms/api/project/plan")
public class ProjectPlanController {

    @Autowired
    private MsProjectService appProjectPlanService;

    /**
     * 获取项目方案列表
     */
    @GetMapping("/list")
    public Result getPlanList(@RequestParam("deptId") Integer deptId,
            @RequestParam(value = "planName", required = false) String planName) {
        List<AppProjectPlan> list = appProjectPlanService.list(deptId, planName);
        return ResultUtil.success(list);
    }

    /**
     * 获取项目方案详情
     */
    @GetMapping("/detail/{id}")
    public Result getPlanDetail(@PathVariable("id") Integer id) {
        AppProjectPlan plan = appProjectPlanService.getById(id);
        return ResultUtil.success(plan);
    }

    /**
     * 新增项目方案
     */
    @PostMapping("/add")
    public Result addPlan(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
            @RequestBody AppProjectPlan plan) {
        plan.setCreateUser(user.getId());
        plan.setUpdateUser(user.getId());
        return ResultUtil.success(appProjectPlanService.save(plan));
    }

    /**
     * 更新项目方案
     */
    @PostMapping("/update")
    public Result updatePlan(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
            @RequestBody AppProjectPlan plan) {
        plan.setUpdateUser(user.getId());
        return ResultUtil.success(appProjectPlanService.update(plan));
    }

    /**
     * 删除项目方案
     */
    @PostMapping("/delete/{id}")
    public Result deletePlan(@PathVariable("id") Integer id) {
        boolean result = appProjectPlanService.delete(id);
        return ResultUtil.success(true);
    }

    /**
     * 批量删除项目方案
     */
    @PostMapping("/deleteBatch")
    public Result deleteBatchPlan(@RequestBody List<Integer> ids) {
        boolean result = appProjectPlanService.deleteBatch(ids);
        return ResultUtil.success(true);
    }



}